<?php

class Person
{
    public $name;
    public $age;
    
    public function __construct($name, $age)
    {
        $this->name = $name;
        $this->age = $age;
    }

    public function say($when,$words)
    {
        echo '我在'.$when.'说了'.$words;
    }
}
$p = new Person('张三',18);

// 反射类
$ref = new ReflectionClass(Person::class);
// $ref = new ReflectionClass($p);
// 获取属性
$properties = $ref->getProperties();
foreach ($properties as $val){
    echo $val->getName().':'.$val->getValue($p)."\n";
}
// 获取方法
$methods = $ref->getMethods();
foreach($methods as $v){
    echo $v->getName()."\n";
    print_r($v->getParameters());
}

// 反射方法
$refm = new ReflectionMethod(Person::class,'say');
// say方法中两个个参数，依次带入
$refm->invoke($p,'早上','你好');
echo "\n";
// say方法两个参数，放到一个数组中
$refm->invokeArgs($p,['今天','天气很热']);





